package b.b.h;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.Window.Callback;
import android.widget.TextView;
import androidx.appcompat.widget.ActionMenuPresenter;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.Toolbar.d;
import b.b.b;
import b.b.g.i.g;
import b.b.g.i.i;
import b.i.k.o;
import b.i.k.t;
import b.i.k.v;
import java.util.Objects;

/* compiled from: ToolbarWidgetWrapper */
public class h0 implements n {
    public Toolbar a;
    public int b;
    public View c;
    public View d;
    public Drawable e;
    public Drawable f;
    public Drawable g;
    public boolean h;
    public CharSequence i;
    public CharSequence j;
    public CharSequence k;
    public Callback l;
    public boolean m;
    public ActionMenuPresenter n;
    public int o = 0;
    public Drawable p;

    /* compiled from: ToolbarWidgetWrapper */
    public class a extends v {
        public boolean a = false;
        public final /* synthetic */ int b;

        public a(int i) {
            this.b = i;
        }

        public void a(View view) {
            this.a = true;
        }

        public void b(View view) {
            if (!this.a) {
                h0.this.a.setVisibility(this.b);
            }
        }

        public void c(View view) {
            h0.this.a.setVisibility(0);
        }
    }

    public h0(Toolbar toolbar, boolean z) {
        this.a = toolbar;
        this.i = toolbar.getTitle();
        this.j = toolbar.getSubtitle();
        this.h = this.i != null;
        this.g = toolbar.getNavigationIcon();
        CharSequence charSequence = null;
        f0 q = f0.q(toolbar.getContext(), null, b.a, 2130968581, 0);
        int i = 15;
        this.p = q.g(15);
        if (z) {
            Toolbar toolbar2;
            Context context;
            TextView textView;
            CharSequence n = q.n(27);
            if (!TextUtils.isEmpty(n)) {
                this.h = true;
                this.i = n;
                if ((this.b & 8) != 0) {
                    this.a.setTitle(n);
                }
            }
            n = q.n(25);
            if (!TextUtils.isEmpty(n)) {
                this.j = n;
                if ((this.b & 8) != 0) {
                    this.a.setSubtitle(n);
                }
            }
            Drawable g = q.g(20);
            if (g != null) {
                this.f = g;
                y();
            }
            g = q.g(17);
            if (g != null) {
                this.e = g;
                y();
            }
            if (this.g == null) {
                g = this.p;
                if (g != null) {
                    this.g = g;
                    x();
                }
            }
            n(q.j(10, 0));
            int l = q.l(9, 0);
            if (l != 0) {
                View inflate = LayoutInflater.from(this.a.getContext()).inflate(l, this.a, false);
                View view = this.d;
                if (!(view == null || (this.b & 16) == 0)) {
                    this.a.removeView(view);
                }
                this.d = inflate;
                if (!(inflate == null || (this.b & 16) == 0)) {
                    this.a.addView(inflate);
                }
                n(this.b | 16);
            }
            l = q.k(13, 0);
            if (l > 0) {
                LayoutParams layoutParams = this.a.getLayoutParams();
                layoutParams.height = l;
                this.a.setLayoutParams(layoutParams);
            }
            l = q.e(7, -1);
            i = q.e(3, -1);
            if (l >= 0 || i >= 0) {
                Toolbar toolbar3 = this.a;
                l = Math.max(l, 0);
                i = Math.max(i, 0);
                toolbar3.d();
                toolbar3.t.a(l, i);
            }
            l = q.l(28, 0);
            if (l != 0) {
                toolbar2 = this.a;
                context = toolbar2.getContext();
                toolbar2.l = l;
                textView = toolbar2.b;
                if (textView != null) {
                    textView.setTextAppearance(context, l);
                }
            }
            l = q.l(26, 0);
            if (l != 0) {
                toolbar2 = this.a;
                context = toolbar2.getContext();
                toolbar2.m = l;
                textView = toolbar2.c;
                if (textView != null) {
                    textView.setTextAppearance(context, l);
                }
            }
            l = q.l(22, 0);
            if (l != 0) {
                this.a.setPopupTheme(l);
            }
        } else {
            if (this.a.getNavigationIcon() != null) {
                this.p = this.a.getNavigationIcon();
            } else {
                i = 11;
            }
            this.b = i;
        }
        q.b.recycle();
        if (2131689473 != this.o) {
            this.o = 2131689473;
            if (TextUtils.isEmpty(this.a.getNavigationContentDescription())) {
                int i2 = this.o;
                if (i2 != 0) {
                    charSequence = getContext().getString(i2);
                }
                this.k = charSequence;
                w();
            }
        }
        this.k = this.a.getNavigationContentDescription();
        this.a.setNavigationOnClickListener(new g0(this));
    }

    public void a(Menu menu, b.b.g.i.m.a aVar) {
        ActionMenuPresenter actionMenuPresenter;
        if (this.n == null) {
            actionMenuPresenter = new ActionMenuPresenter(this.a.getContext());
            this.n = actionMenuPresenter;
            Objects.requireNonNull(actionMenuPresenter);
        }
        actionMenuPresenter = this.n;
        actionMenuPresenter.e = aVar;
        Toolbar toolbar = this.a;
        g gVar = (g) menu;
        if (gVar != null || toolbar.a != null) {
            toolbar.f();
            g gVar2 = toolbar.a.p;
            if (gVar2 != gVar) {
                if (gVar2 != null) {
                    gVar2.u(toolbar.J);
                    gVar2.u(toolbar.K);
                }
                if (toolbar.K == null) {
                    toolbar.K = new d();
                }
                actionMenuPresenter.q = true;
                if (gVar != null) {
                    gVar.b(actionMenuPresenter, toolbar.j);
                    gVar.b(toolbar.K, toolbar.j);
                } else {
                    actionMenuPresenter.c(toolbar.j, null);
                    d dVar = toolbar.K;
                    g gVar3 = dVar.a;
                    if (gVar3 != null) {
                        i iVar = dVar.b;
                        if (iVar != null) {
                            gVar3.d(iVar);
                        }
                    }
                    dVar.a = null;
                    actionMenuPresenter.f(true);
                    toolbar.K.f(true);
                }
                toolbar.a.setPopupTheme(toolbar.k);
                toolbar.a.setPresenter(actionMenuPresenter);
                toolbar.J = actionMenuPresenter;
            }
        }
    }

    public boolean b() {
        return this.a.o();
    }

    public void c() {
        this.m = true;
    }

    public void collapseActionView() {
        i iVar;
        d dVar = this.a.K;
        if (dVar == null) {
            iVar = null;
        } else {
            iVar = dVar.b;
        }
        if (iVar != null) {
            iVar.collapseActionView();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:17:? A:{SYNTHETIC, RETURN} */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x0021  */
    public boolean d() {
        /*
        r4 = this;
        r0 = r4.a;
        r0 = r0.a;
        r1 = 0;
        r2 = 1;
        if (r0 == 0) goto L_0x0022;
    L_0x0008:
        r0 = r0.t;
        if (r0 == 0) goto L_0x001e;
    L_0x000c:
        r3 = r0.v;
        if (r3 != 0) goto L_0x0019;
    L_0x0010:
        r0 = r0.m();
        if (r0 == 0) goto L_0x0017;
    L_0x0016:
        goto L_0x0019;
    L_0x0017:
        r0 = 0;
        goto L_0x001a;
    L_0x0019:
        r0 = 1;
    L_0x001a:
        if (r0 == 0) goto L_0x001e;
    L_0x001c:
        r0 = 1;
        goto L_0x001f;
    L_0x001e:
        r0 = 0;
    L_0x001f:
        if (r0 == 0) goto L_0x0022;
    L_0x0021:
        r1 = 1;
    L_0x0022:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.b.h.h0.d():boolean");
    }

    public boolean e() {
        ActionMenuView actionMenuView = this.a.a;
        if (actionMenuView == null) {
            return false;
        }
        ActionMenuPresenter actionMenuPresenter = actionMenuView.t;
        Object obj = (actionMenuPresenter == null || !actionMenuPresenter.g()) ? null : 1;
        if (obj != null) {
            return true;
        }
        return false;
    }

    public boolean f() {
        return this.a.u();
    }

    public boolean g() {
        Toolbar toolbar = this.a;
        if (toolbar.getVisibility() == 0) {
            ActionMenuView actionMenuView = toolbar.a;
            if (actionMenuView != null && actionMenuView.s) {
                return true;
            }
        }
        return false;
    }

    public Context getContext() {
        return this.a.getContext();
    }

    public CharSequence getTitle() {
        return this.a.getTitle();
    }

    public void h() {
        ActionMenuView actionMenuView = this.a.a;
        if (actionMenuView != null) {
            ActionMenuPresenter actionMenuPresenter = actionMenuView.t;
            if (actionMenuPresenter != null) {
                actionMenuPresenter.b();
            }
        }
    }

    public void i(b.b.g.i.m.a aVar, b.b.g.i.g.a aVar2) {
        Toolbar toolbar = this.a;
        toolbar.L = aVar;
        toolbar.M = aVar2;
        ActionMenuView actionMenuView = toolbar.a;
        if (actionMenuView != null) {
            actionMenuView.u = aVar;
            actionMenuView.v = aVar2;
        }
    }

    public void j(y yVar) {
        View view = this.c;
        if (view != null) {
            ViewParent parent = view.getParent();
            ViewParent viewParent = this.a;
            if (parent == viewParent) {
                viewParent.removeView(this.c);
            }
        }
        this.c = null;
    }

    public ViewGroup k() {
        return this.a;
    }

    public void l(boolean z) {
    }

    public boolean m() {
        d dVar = this.a.K;
        return (dVar == null || dVar.b == null) ? false : true;
    }

    public void n(int i) {
        int i2 = this.b ^ i;
        this.b = i;
        if (i2 != 0) {
            if ((i2 & 4) != 0) {
                if ((i & 4) != 0) {
                    w();
                }
                x();
            }
            if ((i2 & 3) != 0) {
                y();
            }
            if ((i2 & 8) != 0) {
                if ((i & 8) != 0) {
                    this.a.setTitle(this.i);
                    this.a.setSubtitle(this.j);
                } else {
                    this.a.setTitle(null);
                    this.a.setSubtitle(null);
                }
            }
            if ((i2 & 16) != 0) {
                View view = this.d;
                if (view == null) {
                    return;
                }
                if ((i & 16) != 0) {
                    this.a.addView(view);
                } else {
                    this.a.removeView(view);
                }
            }
        }
    }

    public int o() {
        return this.b;
    }

    public Menu p() {
        return this.a.getMenu();
    }

    public void q(int i) {
        this.f = i != 0 ? b.b.d.a.a.b(getContext(), i) : null;
        y();
    }

    public int r() {
        return 0;
    }

    public t s(int i, long j) {
        t a = o.a(this.a);
        a.a(i == 0 ? 1.0f : 0.0f);
        a.c(j);
        a aVar = new a(i);
        View view = (View) a.a.get();
        if (view != null) {
            a.e(view, aVar);
        }
        return a;
    }

    public void setIcon(int i) {
        this.e = i != 0 ? b.b.d.a.a.b(getContext(), i) : null;
        y();
    }

    public void setVisibility(int i) {
        this.a.setVisibility(i);
    }

    public void setWindowCallback(Callback callback) {
        this.l = callback;
    }

    public void setWindowTitle(CharSequence charSequence) {
        if (!this.h) {
            this.i = charSequence;
            if ((this.b & 8) != 0) {
                this.a.setTitle(charSequence);
            }
        }
    }

    public void t() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    public void u() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    public void v(boolean z) {
        this.a.setCollapsible(z);
    }

    public final void w() {
        if ((this.b & 4) == 0) {
            return;
        }
        if (TextUtils.isEmpty(this.k)) {
            this.a.setNavigationContentDescription(this.o);
        } else {
            this.a.setNavigationContentDescription(this.k);
        }
    }

    public final void x() {
        if ((this.b & 4) != 0) {
            Toolbar toolbar = this.a;
            Drawable drawable = this.g;
            if (drawable == null) {
                drawable = this.p;
            }
            toolbar.setNavigationIcon(drawable);
            return;
        }
        this.a.setNavigationIcon(null);
    }

    public final void y() {
        Drawable drawable;
        int i = this.b;
        if ((i & 2) == 0) {
            drawable = null;
        } else if ((i & 1) != 0) {
            drawable = this.f;
            if (drawable == null) {
                drawable = this.e;
            }
        } else {
            drawable = this.e;
        }
        this.a.setLogo(drawable);
    }

    public void setIcon(Drawable drawable) {
        this.e = drawable;
        y();
    }
}
